package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumScriptStatus;
import com.cw.jeeyt.service.bo.api.ApiDatabaseIncrementScriptBo;
import com.cw.jeeyt.dao.model.api.ApiDatabaseIncrementScriptDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 数据库增量脚本转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiDatabaseIncrementScriptConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiDatabaseIncrementScriptBo do2Bo(ApiDatabaseIncrementScriptDo model) {
        if (model == null) {
            return null;
        }
        String scriptStatusCn = StringUtil.isNotBlank(model.getScriptStatus()) ? EnumScriptStatus.find(
            model.getScriptStatus())
            .getDescription() : "";
        ApiDatabaseIncrementScriptBo bo = new ApiDatabaseIncrementScriptBo();
        bo.setId(model.getId());
        bo.setScriptTitle(model.getScriptTitle());
        bo.setScriptStatement(model.getScriptStatement());
        bo.setInputDate(model.getInputDate());
        bo.setScriptStatus(model.getScriptStatus());
        bo.setScriptStatusCn(scriptStatusCn);
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiDatabaseIncrementScriptDo bo2Do(ApiDatabaseIncrementScriptBo bo) {
        if (bo == null) {
            return null;
        }
        ApiDatabaseIncrementScriptDo model = new ApiDatabaseIncrementScriptDo();
        model.setId(bo.getId());
        model.setScriptTitle(bo.getScriptTitle());
        model.setScriptStatement(bo.getScriptStatement());
        model.setInputDate(bo.getInputDate());
        model.setScriptStatus(bo.getScriptStatus());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiDatabaseIncrementScriptBo> doList2BoList(List<ApiDatabaseIncrementScriptDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiDatabaseIncrementScriptConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiDatabaseIncrementScriptDo> boList2DoList(List<ApiDatabaseIncrementScriptBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiDatabaseIncrementScriptConverter::bo2Do));
    }
}
